<#include "*/component/CombineFieldTags.ftl"/>
<@Title>
<#if entity.table.containsCombineColumn>
import ${context.projectPackage}.common.utils.ColumnUtils;
</#if>
</@Title>
<@ClassAnnotation>
@Data
@SqlTarget(target = "${entity.table.name } ${entity.table.alias}")
@SqlTableAlias(alias = "${entity.table.alias}")
</@ClassAnnotation>
<@Class>

${'\t'}@Getter
${'\t'}@NoArgsConstructor
${'\t'}@SqlTableAlias(aliasFromClass = ${clazz.name}.class)
${'\t'}public static class QueryCondition extends NotDeleteCondition {
${'\t'}${'\t'}/**
${'\t'}${'\t'}* 主键
${'\t'}${'\t'}*/
${'\t'}${'\t'}@SqlCondition
${'\t'}${'\t'}@SqlColumn(name = "${entity.primaryField.column.name}")
${'\t'}${'\t'}private ${entity.primaryField.type} ${entity.primaryField.name};
<#list entity.fields as field>
<@Field field=field type=3 tabTimes=2>
${'\t'}${'\t'}@SqlCondition
${'\t'}${'\t'}@SqlColumn(name = "${field.column.name}")
</@Field>
</#list>

${'\t'}${'\t'}public QueryCondition(${entity.primaryField.type} id) {
${'\t'}${'\t'}${'\t'}if (id==null){
${'\t'}${'\t'}${'\t'}${'\t'}throw new BaseException("主键不能为空");
${'\t'}${'\t'}${'\t'}}
${'\t'}${'\t'}${'\t'}this.${entity.primaryField.name} = id;
${'\t'}${'\t'}}

${'\t'}${'\t'}public static QueryConditionBuilder builder(){
${'\t'}${'\t'}${'\t'}return new QueryConditionBuilder();
${'\t'}${'\t'}}

${'\t'}${'\t'}public static class QueryConditionBuilder {
<#--<#list entity.fields as field >-->
<#--    <#if field.column.uniqueKey>-->
<#--        <#if !field.isCombine>-->
<#--${'\t'}${'\t'}${'\t'}private ${field.type} ${field.name};-->
<#--        <#else>-->
<#--            <#list field.combineFields as relationField>-->
<#--${'\t'}${'\t'}${'\t'}private ${relationField.type} ${relationField.name};-->
<#--            </#list>-->
<#--        </#if>-->
<#--    </#if>-->
<#--</#list>-->
    <#list entity.fields as field>
<@Field field=field type=3 tabTimes=3>
${'\t'}${'\t'}${'\t'}@SqlCondition
${'\t'}${'\t'}${'\t'}@SqlColumn(name = "${field.column.name}")
</@Field>
</#list>
<#list entity.fields as field >
<#if field.column.uniqueKey>
${'\t'}${'\t'}${'\t'}public QueryConditionBuilder <@CombineDisplayName field=field/>(<@CombineParam field=field showTpye=true/>) {
${'\t'}${'\t'}${'\t'}${'\t'}this.${field.name} = <@CombineValue field=field/>;
${'\t'}${'\t'}${'\t'}${'\t'}return this;
${'\t'}${'\t'}${'\t'}}
</#if>
</#list>

${'\t'}${'\t'}${'\t'}public QueryCondition build() {
${'\t'}${'\t'}${'\t'}${'\t'}QueryCondition condition = new QueryCondition();
<#list entity.fields as field >
    <#if field.column.uniqueKey>
${'\t'}${'\t'}${'\t'}${'\t'}condition.${field.name}=${field.name};
    </#if>
</#list>
${'\t'}${'\t'}${'\t'}${'\t'}return condition;
${'\t'}${'\t'}${'\t'}}
${'\t'}${'\t'}}

${'\t'}}

    <#list entity.fields as field>
        <@Field field=field useSwagger= true>
${'\t'}@SqlColumn(name = "${field.column.name}")
        </@Field>
    </#list>
${'\t'}/**
${'\t'}* 创建时间
${'\t'}*/
${'\t'}@ApiModelProperty(value = "创建时间")
${'\t'}@SqlColumn(name = "create_time")
${'\t'}private Date createTime;
${'\t'}/**
${'\t'}* 更新时间
${'\t'}*/
${'\t'}@ApiModelProperty(value = "更新时间")
${'\t'}@SqlColumn(name = "update_time")
${'\t'}private Date updateTime;
${'\t'}/**
${'\t'}* 逻辑删除标志
${'\t'}*/
${'\t'}@ApiModelProperty(value = "逻辑删除标志")
${'\t'}@SqlColumn(name = "deleted")
${'\t'}private Boolean deleted;
</@Class>